package com.eedi.framework.errorcode.controller.sys;

import com.eedi.framework.common.pojo.CommonResult;
import com.eedi.framework.errorcode.controller.sys.vo.SysErrorCodeResp;
import com.eedi.framework.errorcode.service.SysErrorCodeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

import static com.eedi.framework.common.pojo.CommonResult.success;


@Tag(name = "系统界面 - 错误码")
@RestController
@RequestMapping("/error-code")
@Validated
public class SysErrorCodeController {

    @Resource
    private SysErrorCodeService sysErrorCodeService;

//    @PostMapping("/create")
//    @Operation(summary = "创建错误码")
//    @PreAuthorize("@sys.hasPermission('sys:error-code:create')")
//    public CommonResult<String> createErrorCode(@Valid @RequestBody SysErrorCodeSaveReq createReqVO) {
//        return success(sysErrorCodeService.createErrorCode(createReqVO));
//    }

//    @PutMapping("/update")
//    @Operation(summary = "更新错误码")
//    @PreAuthorize("@sys.hasPermission('sys:error-code:update')")
//    public CommonResult<Boolean> updateErrorCode(@Valid @RequestBody SysErrorCodeUpReq updateReqVO) {
//        sysErrorCodeService.updateErrorCode(updateReqVO);
//        return success(true);
//    }

//    @DeleteMapping("/delete")
//    @Operation(summary = "删除错误码")
//    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@sys.hasPermission('sys:error-code:delete')")
//    public CommonResult<Boolean> deleteErrorCode(@RequestParam("sysErrorCodeId") String sysErrorCodeId) {
//        sysErrorCodeService.deleteErrorCode(sysErrorCodeId);
//        return success(true);
//    }

//    @GetMapping("/get")
//    @Operation(summary = "获得错误码")
//    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@sys.hasPermission('sys:error-code:query')")
//    public CommonResult<SysErrorCodeResp> getErrorCode(@RequestParam("sysErrorCodeId") String sysErrorCodeId) {
//        SysErrorCodeDO errorCode = sysErrorCodeService.getErrorCode(sysErrorCodeId);
//        return success(BeanUtils.toBean(errorCode, SysErrorCodeResp.class));
//    }

    @GetMapping("/get-by-code")
    @Operation(summary = "获得错误码")
    @Parameter(name = "sysErrorCode", description = "错误码", required = true, example = "1024")
    @PreAuthorize("@sys.hasPermission('sys:error-code:query')")
    public CommonResult<SysErrorCodeResp> getByCode(@RequestParam("sysErrorCode") Integer sysErrorCode) {
        return success(sysErrorCodeService.getByCode(sysErrorCode));
    }

//    @GetMapping("/page")
//    @Operation(summary = "获得错误码分页")
//    @PreAuthorize("@sys.hasPermission('sys:error-code:query')")
//    public CommonResult<PageResult<SysErrorCodeResp>> getErrorCodePage(@Valid SysErrorCodePageReq pageVO) {
//        PageResult<SysErrorCodeDO> pageResult = sysErrorCodeService.getErrorCodePage(pageVO);
//        return success(BeanUtils.toBean(pageResult, SysErrorCodeResp.class));
//    }

}
